#pragma once

#include <d3dx9.h>


struct AABoundingBox;

//-----------------------------------------------------------------------------
// (helper struct)
// the structure describes a mathematical plane
//-----------------------------------------------------------------------------
struct Plane
{
   D3DXVECTOR3 normal;
   float distance;

   Plane() : normal(0, 0, 0), distance(0) {}
};

//-----------------------------------------------------------------------------
// (class)
// The class describes how a view frustrum works and what's visible in it
//-----------------------------------------------------------------------------
class CViewFrustrum
{
private:
   const D3DXMATRIX& m_mtxView;
   const D3DXMATRIX& m_mtxProjection;

public:
   CViewFrustrum(const D3DXMATRIX& m_mtxView, const D3DXMATRIX& m_mtxProjection);

   bool isInside(const AABoundingBox& boundingBox) const;

private:
   void extractFrustrumPlanes(Plane* planes) const;

   D3DXVECTOR3 findNearPoint(const Plane& plane, const AABoundingBox& boundingBox) const;
};
